package cn.shangqizhenshuai.sa.App;

import cn.shangqizhenshuai.core.Core;
import cn.shangqizhenshuai.core.ExecuteCore;
import cn.shangqizhenshuai.entity.TableEntity;
import cn.shangqizhenshuai.info.Inputinfo;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import freemarker.template.TemplateException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class App {


    public static void main(String[] args) throws SQLException, IOException, TemplateException {
        ApplicationContext ac = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
        DruidDataSource dataSource = (DruidDataSource) ac.getBean("dataSource");
        Inputinfo inputinfo = (Inputinfo)ac.getBean("Inputinfo");
        DruidPooledConnection connection = dataSource.getConnection();
        Core core = new Core();
        core.setInputinfo(inputinfo);
        //查询基本表信息
        List<TableEntity> selecttabcolumn = core.selecttabcolumn(connection);
        HashMap<String, List> context = new HashMap<String, List>();
        context.put("tabinfo",selecttabcolumn);
        //添加至总上下文系统
        ExecuteCore executeCore = (ExecuteCore)ac.getBean("executeCore");
        executeCore.setContext(context);
        //开始执行
        executeCore.execute(context);
//        for (TableEntity tableEntity : selecttabcolumn) {
//            for (TableEntity entity : selecttabcolumn) {
//                System.out.println("表名称为"+entity.getTabname());
//                System.out.println("类型为"+entity.getTabtype());
//                for (ColumnEntity columnEntity : entity.getColumnEntitys()) {
//                    System.out.println(columnEntity.isCOLUMN_KEY());
//                    System.out.println(columnEntity.getCOLUMN_NAME());
//                    System.out.println(columnEntity.getDATA_TYPE());
//                    System.out.println(columnEntity.isIS_NULLABLE());
//                }
//            }
//        }

    }
}
